﻿#region USING STATEMENTS
using System;
using Microsoft.Xna.Framework;
using Fusion.Management;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
#endregion

#region CODE BODY
namespace Fusion
{
    public class FusionGame : Game
    {
        ////////////////////////////////////////////////////////////////////
        // Data Fields
        ////////////////////////////////////////////////////////////////////
        private static GraphicsDeviceManager Graphics;
        private static Canvas Batch;
        private static Int32 BufferWidth, BufferHeight;
        private static string LightEffectFile;
        public static FusionGame MainGame;
        public static GameTime CurrentTime;

        ////////////////////////////////////////////////////////////////////
        // Constructors
        ////////////////////////////////////////////////////////////////////
        public FusionGame(Int32 BackBufferWidth, Int32 BackBufferHeight, Boolean MouseVisible, string LightEngineEffect)
        {
            Graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            Graphics.PreferredBackBufferWidth = BackBufferWidth;
            Graphics.PreferredBackBufferHeight = BackBufferHeight;
            Graphics.GraphicsProfile = GraphicsProfile.HiDef;
            BufferWidth = BackBufferWidth;
            BufferHeight = BackBufferHeight;
            LightEffectFile = LightEngineEffect;

            FStates.ScreenRect = new Rectangle(0, 0, BackBufferWidth, BackBufferHeight);
            IsMouseVisible = MouseVisible;

            System.Windows.Forms.Form GameWindow = (System.Windows.Forms.Form)(System.Windows.Forms.Form.FromHandle(this.Window.Handle));
            GameWindow.ControlBox = false;

            MainGame = this;
        }

        ////////////////////////////////////////////////////////////////////
        // Game Methods
        ////////////////////////////////////////////////////////////////////
        protected override void Initialize()
        {
            base.Initialize();
        }
        protected override void LoadContent()
        {
            Batch = new Canvas(GraphicsDevice);

            FContent.SetContent(Content);
            FCanvas.SetCanvas(Batch);

            FLights.InitializeLightEngine(GraphicsDevice, BufferWidth, BufferHeight, LightEffectFile);
        }
        protected override void UnloadContent()
        {
            FTextures.ReleaseAllTextures();
            FAudio.ReleaseAllEffects();
            FAudio.ReleaseAllSongs();
        }
        protected override void Update(GameTime Time)
        {
            CurrentTime = Time;
            float Delta = (float)Time.ElapsedGameTime.TotalSeconds;

            FInput.BeginPoll();
            FJoystick.BeginPoll();

            if (!FStates.Update(Delta))
                this.Exit();

            if (FInput.KeyPressed(Keys.F4))
                Graphics.ToggleFullScreen();

            FLights.SetGameTime(Time);

            base.Update(Time);
        }
        protected override void Draw(GameTime Time)
        {
            FInput.EndPoll();
            FJoystick.EndPoll();

            Single Delta = (Single)Time.ElapsedGameTime.TotalSeconds;

            FStates.Render(Delta);

            base.Draw(Time);
        }
    }
}
#endregion

//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright 2012 Jeffery Thomas Sventora
//////////////////////////////////////////////////////////////////////////////////////////////